ARD2  RC2
Airbag Reference Demonstrator using MPC5604P
freemaster_MPC56xx.c
Go to the documentation of this file.
00001 /******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2010 Freescale Semiconductor
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************/
00019 #include "freemaster.h"
00020 #include "freemaster_private.h"
00021 #include "freemaster_MPC56xx.h"
00022 
00023 /*******************************************************************************
00024 *
00025 * @brief    API: Main SCI Interrupt handler call
00026 *
00027 * This Interrupt Service Routine handles the SCI interrupts for the FreeMASTER
00028 * driver. In case you want to handle the interrupt in the application yourselves,
00029 * call the FMSTR_ProcessSCI function which does the same job but is not compiled
00030 * as an Interrupt Service Routine.
00031 *
00032 * In poll-driven mode (FMSTR_POLL_DRIVEN) this function does nothing.
00033 *
00034 *******************************************************************************/
00035 
00036 void FMSTR_Isr(void)
00037 {
00038 #if FMSTR_LONG_INTR || FMSTR_SHORT_INTR
00039 
00040     /* process serial interface */
00041 #if FMSTR_USE_SCI
00042     FMSTR_ProcessSCI();
00043 
00044     /* process CAN interface */
00045 #elif FMSTR_USE_CAN
00046     FMSTR_ProcessCanRx();
00047     FMSTR_ProcessCanTx(); 
00048 #endif
00049 
00050 #endif
00051 }
00052 
00053 /**************************************************************************/
00063 void FMSTR_CopyMemory(FMSTR_ADDR nDestAddr, FMSTR_ADDR nSrcAddr, FMSTR_SIZE8 nSize)
00064 {
00065     FMSTR_U8* ps = (FMSTR_U8*) nSrcAddr;
00066     FMSTR_U8* pd = (FMSTR_U8*) nDestAddr;
00067 
00068     while(nSize--)
00069         *pd++ = *ps++;
00070 }
00071 
00072 /**************************************************************************/
00084 FMSTR_BPTR FMSTR_CopyToBuffer(FMSTR_BPTR pDestBuff, FMSTR_ADDR nSrcAddr, FMSTR_SIZE8 nSize)
00085 {
00086     FMSTR_U8* ps = (FMSTR_U8*) nSrcAddr;
00087     FMSTR_U8* pd = (FMSTR_U8*) pDestBuff;
00088 
00089     while(nSize--)
00090         *pd++ = *ps++;
00091 
00092     return (FMSTR_BPTR) pd;
00093 }
00094 
00095 /**************************************************************************/
00107 FMSTR_BPTR FMSTR_CopyFromBuffer(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR_SIZE8 nSize)
00108 {
00109     FMSTR_U8* ps = (FMSTR_U8*) pSrcBuff;
00110     FMSTR_U8* pd = (FMSTR_U8*) nDestAddr;
00111 
00112     while(nSize--)
00113         *pd++ = *ps++;
00114 
00115     return (FMSTR_BPTR) ps;
00116 }
00117 
00118 
00119 /**************************************************************************/
00129 void FMSTR_CopyFromBufferWithMask(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR_SIZE8 nSize)
00130 {
00131     FMSTR_U8* ps = (FMSTR_U8*) pSrcBuff;
00132     FMSTR_U8* pd = (FMSTR_U8*) nDestAddr;
00133     FMSTR_U8* pm = ps + nSize;
00134     FMSTR_U8 mask, stmp, dtmp;
00135 
00136     while(nSize--)
00137     {
00138         mask = *pm++;
00139         stmp = *ps++;
00140         dtmp = *pd;
00141 
00142         /* perform AND-masking */
00143         stmp = (FMSTR_U8) ((stmp & mask) | (dtmp & ~mask));
00144 
00145         /* put the result back       */
00146         *pd++ = stmp;
00147     }
00148 }
00149 
00150 /******************************************************************************/
00151 
00152 /* mixed EX and no-EX commands? */
00153 #if FMSTR_USE_EX_CMDS && FMSTR_USE_NOEX_CMDS
00154 
00155 /**************************************************************************/
00162 static FMSTR_BOOL pcm_bNextAddrIsEx;
00163 
00164 void FMSTR_SetExAddr(FMSTR_BOOL bNextAddrIsEx)
00165 {
00166     pcm_bNextAddrIsEx = bNextAddrIsEx;
00167 }
00168 
00169 /**************************************************************************/
00176 FMSTR_BPTR FMSTR_AddressToBuffer(FMSTR_BPTR pDest, FMSTR_ADDR nAddr)
00177 {
00178     if(pcm_bNextAddrIsEx)
00179     {
00180         /* fill in the 32bit address */
00181         *(FMSTR_U32*) pDest = ((FMSTR_U32)nAddr);
00182         pDest += 4;
00183     }
00184     else
00185     {
00186         /* fill in the 16bit address (never used) */
00187         *(FMSTR_U16*) pDest = ((FMSTR_U16)nAddr);
00188         pDest += 2;
00189     }
00190 
00191     return pDest;
00192 }
00193 
00194 /**************************************************************************/
00200 FMSTR_BPTR FMSTR_AddressFromBuffer(FMSTR_ADDR* pAddr, FMSTR_BPTR pSrc)
00201 {
00202     if(pcm_bNextAddrIsEx)
00203     {
00204         *pAddr = (FMSTR_ADDR) *((FMSTR_U32*) pSrc);
00205         pSrc += 4;
00206     }
00207     else
00208     {
00209         *pAddr = (FMSTR_ADDR) *((FMSTR_U16*) pSrc);
00210         pSrc += 2;
00211     }
00212 
00213     return pSrc;
00214 }
00215 
00216 #endif /* mixed EX and no-EX commands */